<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cap.bean.User" %>
<%@ page import="cap.bean.Article" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
    User u = (User)request.getSession().getAttribute("user");//用户资料
    List<Article> artList = (List<Article>)request.getAttribute("artList");//个人博文信息
//添加下面两行代码用于分页显示
//    int curPage = (Integer)request.getAttribute("curPage");
    int totalPages = (Integer)request.getAttribute("totalPages");
    String succMsg = (String)request.getSession().getAttribute("succMsg");	//新建文章成功
    String errorMsg = (String)request.getSession().getAttribute("errorMsg");//新建文章错误
    String deleSuccMsg = (String)request.getSession().getAttribute("deleSuccMsg");	//删除文章成功
    String deleErrorMsg = (String)request.getSession().getAttribute("deleErrorMsg");//删除文章错误
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>博客</title>
    <link href="<%=basePath%>bootstrap/css/blog-home.css"/>
    <link href="<%=basePath%>bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="<%=basePath%>bootstrap/js/jquery-2.1.1.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"><!--导航条、反色、固定在顶部 -->
    <div class="container"><!--将导航条居中对齐并在两侧添加内补 -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">博客</a><!--设置了内补（padding）和高度（height） -->
        </div>
        <!--导航链接，表格，和切换其他内容-->
        <div class="collapse navbar-collapse"><!--依赖collapse插件、视口足够窄.navbar-collapse内所包含的内容也将不可见-->
            <ul class="nav navbar-nav"><!--导航、导航项-->
                <li><a href="<%=path%>/user?method=index">网站首页</a></li>
            </ul>
            <c:if test="${null!=user&&user.getIsApplied() == 1}">
                <ul class="nav navbar-nav">
                    <li><a href="<%=basePath%>user?method=myblog&userId=${user.id}">我的博客</a></li>
                    <li><a href="<%=basePath%>article?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 博文管理</a></li><!--Glyphicons字体图标-->
                    <li class="divider"></li><!--分割线-->
                    <li><a href="<%=basePath%>category?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 分类管理</a></li><!--Glyphicons字体图标-->
                    <li class="divider"></li>
                    <li><a href="<%=basePath%>comment?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 评论管理</a></li>
                </ul>
            </c:if>
            <c:if test="${user==null}">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="<%=path%>/login.jsp" target="_self">登录</a></li>
                    <li><a href="<%=path%>/register.jsp" target="_self">注册</a></li>
                </ul>
            </c:if>
            <c:if test="${user!=null}">
                <div class="pull-right">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#">欢迎，${user.userName}</a></li>
                        <li><a href="<%=basePath%>user?method=profile&id=${user.id}"><i class="glyphicon glyphicon-cog"></i> 编辑个人信息</a></li>
                        <c:if test="${user.isApplied==1}">
                            <li><a href="<%=basePath%>user?method=bloginfo&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 编辑博客信息</a></li>
                        </c:if>
                        <li><a href="<%=path%>/user?method=logout"><i class="glyphicon glyphicon-off"></i> 登出</a></li>
                    </ul>
                    </li>
                    </ul>
                </div>
            </c:if>
        </div>
    </div>
</nav>
<c:if test="${null != succMsg}">
    <div class="container" style="position: absolute;top: 55px;left:340px">
        <div class="alert alert-success">${succMsg}</div>
    </div>
    <%
        request.getSession().removeAttribute("succMsg");
    %>
</c:if>
<c:if test="${null != errorMsg}">
    <div class="container" style="position: absolute;top: 55px;left:340px;">
        <div class="alert alert-error">${errorMsg}</div>
    </div>
    <%
        request.getSession().removeAttribute("errorMsg");
    %>
</c:if>
<c:if test="${null != deleSuccMsg}">
    <div class="container" style="position: absolute;top: 55px;left:340px;">
        <div class="alert alert-success">${deleSuccMsg}</div>
    </div>
    <%
        request.getSession().removeAttribute("deleSuccMsg");
    %>
</c:if>
<c:if test="${null != deleErrorMsg}" >
    <div class="container" style="position: absolute;top: 55px;left: 340px">
        <div class="alert alert-error">${deleErrorMsg}</div>
    </div>
    <%
        request.getSession().removeAttribute("deleErrorMsg");
    %>
</c:if>
<c:if test="${null!=user}">
    <div class="container" style="position:absolute;top: 110px;left: 340px">
        <div class="btn-toolbar">
            <a class="btn btn-primary"
               href="<%=basePath%>article?method=add&userId=${user.id}">新建文章</a>
        </div>
        <div class="well">
            <table class="table"><!--列表-->
                <thead>
                <tr>
                    <th>标题</th>
                    <th>系统分类</th>
                    <th>个人分类</th>
                    <th>最近一次修改时间</th>
                    <th style="width: 50px;">操作</th>
                </tr>
                </thead>
                <tbody>
                <%

                    if (null != artList) {
                        for (Article art : artList) {
                            if (0 == art.getIsDelete()) { //文章管理界面不显示删除的文章
                                String deleUrl = basePath+ "article?method=delete&artId="+ art.getId() + "&userId=" + u.getId(); //删除链接
                %>
                <tr>
                    <td><a
                            href="<%=basePath %>article?method=update&artId=<%=art.getId() %>"><%=art.getTitle() %></a></td>
                    <td><%=art.getScName()%></td>
                    <td><%=art.getCategoryName() %></td>
                    <td><%=art.getPublishTime() %></td>
                    <td><a
                            href="<%=basePath %>article?method=update&artId=<%=art.getId() %>"><i
                            class="glyphicon glyphicon-pencil"></i></a> <a
                            onClick="dele('<%=deleUrl %>')"><i
                            class="glyphicon glyphicon-remove"></i></a></td><!--编辑删除图标-->
                </tr>
                <%     }
                }
                } else { %>
                <% } %>
                </tbody>
            </table>
        </div>
        <div>
            <!-- pager -->
            <ul class="pager">
                <c:if test="${curPage > 1}">
                    <li class="previous"><a
                            href="<%=basePath%>article?method=manage&userId=${user.id}&curPage=${curPage-1}">&larr;
                        上一页</a></li>
                </c:if>
                <c:if test="${curPage < totalPages}">
                    <li class="next"><a href="<%=basePath%>article?method=manage&userId=${user.id}&curPage=${curPage+1}">下一页
                        &rarr;</a></li>
                </c:if>
            </ul>
        </div>

    </div>
</c:if>
<div class="container" style="position: absolute;bottom: 10px;left: 400px">
    <hr>
    <footer style="text-align: center">
        <div class="row">
            <div class="col-lg-12">
                <p>
                    &middot;网站创建到目前访问人数：<%=(Integer)session.getAttribute("num") %>
                </p>
            </div>
        </div>
    </footer>
</div>
<div><audio autoplay="autoplay" loop="true"><source src="music/1.mp3"></audio></div>
</body>
<script type="text/javascript">
    function dele(deleUrl) {

        if (confirm("你确定要删除这篇文章吗？")) {
            location.href = deleUrl;
        }
    }
</script>
</html>